package com.lm.chronicle.consumer;

import com.lm.chronicle.entry.Order;
import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptTailer;

public class CustomObjectConsumer {
    public static void main(String[] args) {
        // 读取生产者存储的队列数据
        try (ChronicleQueue queue = ChronicleQueue.single("./data/queue")) {
            ExcerptTailer tailer = queue.createTailer();

            // 循环读取消息
            while (true) {
                boolean found = tailer.readDocument(w -> {
                    String message = w.read("data").text();
                    System.out.println("Consumed: " + message);
                });

                // 如果队列中没有新消息，等待
                if (!found) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        break;
                    }
                }
            }
        }
    }
}